package com.syys.privacy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.syys.common.annotation.Log;
import com.syys.common.enums.BusinessType;
import com.syys.privacy.domain.PrivacyInfoUse;
import com.syys.privacy.service.IPrivacyInfoUseService;
import com.syys.common.core.controller.BaseController;
import com.syys.common.core.domain.AjaxResult;
import com.syys.common.utils.poi.ExcelUtil;
import com.syys.common.core.page.TableDataInfo;

/**
 * 收集、使用个人信息的目的及范围Controller
 *
 * @author ys
 * @date 2021-07-15
 */
@Controller
@RequestMapping("/privacy/use")
public class PrivacyInfoUseController extends BaseController {
    private String prefix = "privacy/use";

    @Autowired
    private IPrivacyInfoUseService privacyInfoUseService;

//    @RequiresPermissions("privacy:use:view")
    @GetMapping()
    public String use() {
        return prefix + "/use";
    }

    /**
     * 查询收集、使用个人信息的目的及范围列表
     */
//    @RequiresPermissions("privacy:use:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PrivacyInfoUse privacyInfoUse) {
        startPage();
        List<PrivacyInfoUse> list = privacyInfoUseService.selectPrivacyInfoUseList(privacyInfoUse);
        return getDataTable(list);
    }

    /**
     * 导出收集、使用个人信息的目的及范围列表
     */
//    @RequiresPermissions("privacy:use:export")
    @Log(title = "收集、使用个人信息的目的及范围", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PrivacyInfoUse privacyInfoUse) {
        List<PrivacyInfoUse> list = privacyInfoUseService.selectPrivacyInfoUseList(privacyInfoUse);
        ExcelUtil<PrivacyInfoUse> util = new ExcelUtil<PrivacyInfoUse>(PrivacyInfoUse.class);
        return util.exportExcel(list, "收集、使用个人信息的目的及范围数据");
    }

    /**
     * 新增收集、使用个人信息的目的及范围
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存收集、使用个人信息的目的及范围
     */
//    @RequiresPermissions("privacy:use:add")
    @Log(title = "收集、使用个人信息的目的及范围", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PrivacyInfoUse privacyInfoUse) {
        return  AjaxResult.success(privacyInfoUseService.insertPrivacyInfoUse(privacyInfoUse));
    }

    /**
     * 修改收集、使用个人信息的目的及范围
     */
    @GetMapping("/edit/{infoUseId}")
    public String edit(@PathVariable("infoUseId") Long infoUseId, ModelMap mmap) {
        PrivacyInfoUse privacyInfoUse = privacyInfoUseService.selectPrivacyInfoUseById(infoUseId);
        mmap.put("privacyInfoUse", privacyInfoUse);
        return prefix + "/edit";
    }

    /**
     * 修改保存收集、使用个人信息的目的及范围
     */
//    @RequiresPermissions("privacy:use:edit")
    @Log(title = "收集、使用个人信息的目的及范围", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PrivacyInfoUse privacyInfoUse) {
        return toAjax(privacyInfoUseService.updatePrivacyInfoUse(privacyInfoUse));
    }

    /**
     * 删除收集、使用个人信息的目的及范围
     */
//    @RequiresPermissions("privacy:use:remove")
    @Log(title = "收集、使用个人信息的目的及范围", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(privacyInfoUseService.deletePrivacyInfoUseByIds(ids));
    }
}
